import { createRouter, createWebHistory } from "vue-router";
import TabsView from "../views/tabs/TabsView.vue";
import HomeView from "@/views/tabs/home/HomeView.vue";
import CartView from "@/views/tabs/cart/CartView.vue";
import ChatView from "@/views/tabs/chat/ChatView.vue";
import MeView from "@/views/tabs/me/MeView.vue";
import TypeView from "@/views/tabs/type/TypeView.vue";
import SearchView from "@/views/tabs/type/SearchView.vue";//搜索页面
import DingView from "@/views/tabs/cart/DingView.vue";//确认订单页面
import TiView from "@/views/tabs/cart/TiView.vue";//选择提货点页面
import XiangView from "@/views/tabs/type/XiangView.vue";//列表详情页面
import XiangsView from "@/views/tabs/type/XiangsView.vue";//购物车详情
import DanView from "@/views/tabs/cart/DanView.vue";//我的订单

import Talking from "@/views/tabs/chat/Talking.vue";
import CurrentLogin from "@/views/tabs/chat/CurrentLogin.vue";
import AIChat from "@/views/tabs/chat/AIChat.vue";

//zhc
import Login from "@/views/login/Login.vue";
import FaceLogin from "@/views/login/faceLogin.vue";
import WelcomeLogin from "@/views/login/WelcomeLogin.vue";
import PsdLogin from "@/views/login/psdLogin.vue";
import BindFace from "@/views/login/BindFace.vue"
import ForgotPsd from "@/views/login/ForgotPsd.vue";
import NewPsd from "@/views/login/NewPsd.vue";
import Register from "@/views/login/Register.vue";

// lzl
// 设置
import Setting from "@/views/tabs/setting/Setting.vue";
// 修改用户信息
import Setinfo from "@/views/tabs/me/Setinfo.vue";
import shopStatus from "@/views/tabs/me/shopStatus.vue";

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      name: "tabs",
      component: TabsView,
      redirect: "/home",
      children: [
        { path: "/home", name: "home", component: HomeView },
        { path: "/chat", name: "chat", component: ChatView },
        { path: "/me", name: "me", component: MeView },
        { path: "/type", name: "type", component: TypeView },
      ],
    },
    { path: "/setting", name: "setting", component: Setting },
    { path: "/setinfo", name: "Setinfo", component: Setinfo },
    { path: "/shopstatus", name: "shopStatus", component: shopStatus },

    {
      path: "/login",
      name: "login",
      component: Login,
    },
    { path: "/sear", name: "sear", component: SearchView },
    { path: "/ti", name: "ti", component: TiView },
    { path: "/dan", name: "dan", component: DanView },
    { path: "/xiang", name: "xiang", component: XiangView },
    { path: "/xiangs", name: "xiangs", component: XiangsView },
    { path: "/cart", name: "cart", component: CartView },
    { path: "/ding", name: "ding", component: DingView },
    { path: "/current_login", name: "current_login", component: CurrentLogin },
    { path: "/ai_chat", name: "ai_chat", component: AIChat },
    { path: "/talking", name: "talking", component: Talking },
    { path: "/login", name: "login", component: Login },
    { path: "/welcomeLogin", name: "welcomeLogin", component: WelcomeLogin },
    { path: "/faceLogin", name: "faceLogin", component: FaceLogin },
    { path: "/psdLogin", name: "psdLogin", component: PsdLogin },
    { path: "/bindface", name: "bindface", component: BindFace },
    { path: "/forgotPsd", name: "forgotPsd", component: ForgotPsd },
    { path: "/newPsd", name: "newPsd", component: NewPsd },
    { path: "/register", name: "register", component: Register },
    { path: "/", redirect: "/login" },
  ],
});


// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login'
    || to.path === '/welcomeLogin'
    || to.path === '/faceLogin'
    || to.path === '/psdLogin'
    || to.path === '/register'
    || to.path === '/forgotPsd'
    || to.path === '/newPsd' || to.path === '/bindface') {
    next()
  } else {
    const token = localStorage.getItem('refreshToken')
    !token ? next('/login') : next()
  }
})
export default router;
